package com.loong.shop.controller.forehead;

import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonValidate;
import com.loong.shop.common.forehead.param.GoodsBaseQueryForeheadParam;
import com.loong.shop.handler.GoodsBaseHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description: 处理前台商品请求的Controller
 * @Author: 刘群
 * @Date: 2020/10/27 8:55
 */
@RestController
@RequestMapping("forehead/shop/goodsBase")
public class GoodsBaseForeheadController extends BaseForeheadController {

    @Resource
    private GoodsBaseHandler baseHandler;

    /**
     * 分页进行联合查询商品列表
     * @param param 查询参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/goodsList")
    public Result pageQueryGoodsBaseListToForehead(@RequestBody GoodsBaseQueryForeheadParam param){
        return handlerExecutor.execute(() -> baseHandler.pageQueryGoodsBaseListToForehead(param));
    }

    /**
     * 点赞商品
     * @param param 商品id
     * @return 响应的结果
     */
    @PostMapping("like")
    public Result likeGoodsBase(@RequestBody @Validated({CommonValidate.class}) BaseIdParam param){
        return handlerExecutor.execute(() -> baseHandler.likeGoodsBase(param.getId()));
    }

    /**
     * 更新商品的点赞数
     * @param param 商品id
     * @return 响应的结果
     */
    @PostMapping("updateLikeNum")
    public Result updateGoodsBaseLikNum(@RequestBody @Validated({CommonValidate.class}) BaseIdParam param){
        return handlerExecutor.execute(() -> baseHandler.updateGoodsBaseLikNum(param.getId()));
    }
}
